  <!-- 赚钱 -->

<script>
import { reactive, toRefs } from "@vue/reactivity";
import navfooterView from "../components/navfooterView.vue";
import { onBeforeUnmount } from "@vue/runtime-core";
import { Toast } from "vant";
import { useRouter } from "vue-router";
import { onMounted } from "vue";
export default {
  setup(_, { emit }) {
    let list = reactive({
      times: 0,
      merk: 0, //金额
      lists: [
        {
          emid: 1,
          num: 1000,
          checed: true,
          btn_flag: false,
        },
        {
          emid: 2,
          num: 2000,
          checed: false,
          btn_flag: false,
        },
        {
          emid: 3,
          num: 3000,
          checed: false,
          btn_flag: false,
        },
        {
          emid: 5,
          num: 5000,
          checed: false,
          btn_flag: false,
        },
        {
          emid: 10,
          num: 10000,
          checed: false,
          btn_flag: false,
        },
      ],
      Signinlist: [
        {
          id: 1,
          flag: false,
        },
        {
          id: 2,
          flag: false,
        },
        {
          id: 3,
          flag: false,
        },
        {
          id: 4,
          flag: false,
        },
        {
          id: 5,
          flag: false,
        },
        {
          id: 6,
          flag: false,
        },
        {
          id: 7,
          flag: false,
        },
      ],
      maknei: 0, //金币
      yuan: 0, //钱
      show_flag: false,
      numlist: [], //存储充值金额
      nums: 0,
      Unlocklist: [], //购买章节数组
      Signin_index: 1,
    });
    const router = useRouter();

    let Signlist = JSON.parse(localStorage.getItem('Signin'))
    if (Signlist && Signlist.length) {
      list.Signinlist = Signlist
    }else{
      list.Signinlist
    }


    let Signintype = JSON.parse(localStorage.getItem('Signintype'))
    if (Signintype && Signintype.length) {
      list.Signin_index = Signintype[0].index
      list.show_flag = Signintype[0].flag
    }else{
      list.show_flag
       list.Signin_index
    }
    






    onMounted(() => {
      //解锁章节  Unlock
      if (window.localStorage.getItem("Unlock") == null) {
        window.localStorage.setItem("Unlock", "[]");
      }

      //解锁章节初始化
      let Unlock = window.localStorage.getItem("Unlock");
      list.Unlocklist = JSON.parse(Unlock);
      //本地存储熊猫币
      if (window.localStorage.getItem("panda") == null) {
        window.localStorage.setItem("panda", "[]");
      }
      let panda = window.localStorage.getItem("panda");
      panda = JSON.parse(panda);
      list.numlist = panda;
      getnums();
    });






    //计算熊猫币
    let getnums = () => {
      list.nums = list.numlist.reduce((total, item) => {
        return (total += item.num);
      }, 0);
      if (list.Unlocklist.length > 0) {
        list.nums = list.nums - list.Unlocklist.length * 12;
        console.log(list.nums, "余额");
      }
    };
    emit("updatedcount", router);

    let datalist = JSON.parse(localStorage.getItem("comple"));
    if (datalist && datalist.length) {
      list.lists = datalist;
    } else {
      list.lists;
    }
    let makneilist = JSON.parse(localStorage.getItem("maknei"));
    if (makneilist) {
      list.maknei = makneilist;
    } else {
      list.maknei = 0;
    }
    let yuanlist = JSON.parse(localStorage.getItem("yuan"));
    if (yuanlist) {
      list.yuan = yuanlist;
    } else {
      list.yuan = 0;
    }

    // 计算今天阅读时间
    let time = JSON.parse(localStorage.getItem("time"));
    if (time) {
      // 拿去阅读时间数据
      let aa = time[0].into;
      let bb = time[0].leave;
      list.times = bb - aa;
      // 计算阅读数据
      list.times = Math.ceil(list.times / 1000 / 60 / 60);
    } else {
      list.times = 0;
    }

    //计算总金币
    let panda = JSON.parse(localStorage.getItem("panda"));
    if (panda) {
      console.log(panda);
      panda.forEach((item) => {
        list.merk += item.num;
      });
    } else {
      list.merk = 0;
    }

    // 领取金币
    let btnFun = (id) => {
      let index = list.lists.findIndex((item) => item.emid == id);
      Toast({
        message: "成功领取" + list.lists[index].num + "金币",
        icon: "like-o",
      });

      Toast({
        message: "领取" + list.lists[index].num + "金币成功",
        icon: "",
      });
      list.lists[index].btn_flag = true;
      list.maknei += list.lists[index].num;
    };

    let comple = JSON.parse(localStorage.getItem("comple"));
    if (comple) {
      console.log(list.merk, "11");
      list.lists.forEach((item) => {
        if (item.emid <= list.times) {
          item.checed = true;
        } else {
          item.checed = false;
        }
      });
      console.log(list.lists, "信息");
    } else {
      localStorage.setItem("comple", JSON.stringify(list.lists));
    }

    onBeforeUnmount(() => {
      localStorage.setItem("comple", JSON.stringify(list.lists));
      localStorage.setItem("maknei", JSON.stringify(list.maknei));
      localStorage.setItem("Signin", JSON.stringify(list.Signinlist));
      let boxsi = []
      boxsi.push({
        index:list.Signin_index,
        flag:list.show_flag
      })
      localStorage.setItem('Signintype',JSON.stringify(boxsi))
    });

    let addFun = () => {
      router.push("/cash");
    };
    let parFun = () => {
      router.push("/cash");
    };

    // 签到
    let SigninFun = () => {
      list.show_flag = true;
      list.Signinlist[list.Signin_index - 1].flag = true;
      let num = Math.floor(Math.random() * 10000 + 1000)
        list.maknei += num
      Toast({
        message: "签到成功获得+" + num,
        icon: "",
      });
    };
    // 视频
    let videoFun = () => {
      Toast.fail("今日已完成签到");
    };

    return {
      ...toRefs(list),
      SigninFun,
      videoFun,
      btnFun,
      addFun,
      parFun,
      getnums,
    };
  },
  components: {
    navfooterView,
  },
};
</script>



<template>
  <div class="app-make">
    <div class="head-Mask"></div>
    <div class="head">
      <span class="head-text">福利中心</span>
      <span class="head-con">
        <!-- <span class="con-bz"><img src="../assets/img/am2.png" alt="" /></span> -->
      </span>
    </div>
    <div class="content">
      <!-- 内容头部 -->
      <div class="content-head">
        <div>
          <div class="con-text">
            <i>{{ nums }}</i> 币
          </div>
          <div class="content-con">熊猫币</div>
        </div>
        <div>
          <div class="con-text">
            <i>{{ maknei }}</i> 金币
          </div>
          <div class="content-con" @click="addFun">兑换现金</div>
        </div>
        <div>
          <div class="con-text">
            <i>{{ yuan }}</i
            >元
          </div>
          <div class="content-con" @click="parFun">可提现</div>
        </div>
      </div>
      <!-- 签到块 -->
      <div class="content-Sign">
        <div class="Sign-ul">
          <div>
            <div class="sign-span1">每天签到有礼</div>
            <div class="sign-span2">连续签到可获得高额奖励</div>
          </div>
          <!-- <div class="sign-con">漏签3天</div> -->
        </div>
        <div class="Countersign">
          <div class="Countersign-ul">
            <div
              class="Countersign-lis"
              v-for="(item, index) in Signinlist"
              :key="index"
            >
              <div class="Countersign-li1" v-if="!item.flag">
                <div class="li1-con"></div>
                <div class="li1-text">{{ index + 1 }}天</div>
              </div>
              <div class="Countersign-li2" v-if="item.flag">
                <div class="li2-con"></div>
                <div class="li2-text">已签</div>
              </div>
            </div>
          </div>
        </div>
        <div class="Sign-Button">
          <div class="button-submit" v-if="!show_flag" @click="SigninFun">
            <i></i>立即签到
          </div>
          <div
            class="button-submit button-submit1"
            v-if="show_flag"
            @click="videoFun"
          >
            签到成功
          </div>
        </div>
        <div class="Sign-member">
          <i class="i1"></i>
          <div class="member-text1">开通会员可获得更多签到奖励</div>
          <div class="member-text2">
            <span>签到规则</span>
            <span class="iconfont icon">&#xe655;</span>
          </div>
        </div>
      </div>

      <!-- 视频阅读区 -->
      <div class="content-video">
        <div class="Daily">
          <div class="Daily-ul">
            <div class="Daily-li1">每日阅读有礼</div>
            <div class="Daily-li2">读的越多，奖励越多</div>
          </div>
          <div class="Daily-span">
            <span class="span-text"
              >今日已阅读 <i> {{ times }} </i> 分钟</span
            >
          </div>
        </div>

        <main v-for="item in lists" :key="item.emid">
          <div class="video-Gold goids" v-if="!item.checed">
            <div class="Gold-uls">
              <div class="Gold-ul1">
                <span class="Gold-li1"
                  >阅读 &nbsp;{{ item.emid }}&nbsp; 分钟</span
                >
                <span class="Gold-li2"
                  ><i class="li2-con"></i>{{ item.num }} 金币</span
                >
                <!-- <span class="Gold-li2 goids-li2">
                <i class="li2-con lis-con"></i>100礼卷</span> -->
              </div>
              <div class="Gold-ul2">每天一阅,来阅读吧</div>
            </div>
            <span class="Gold-span goids-span">未完成</span>
          </div>
        </main>
        <main v-for="item in lists" :key="item.emid">
          <div class="video-Gold goids" v-if="item.checed">
            <div class="Gold-uls">
              <div class="Gold-ul1">
                <span class="Gold-li1">
                  阅读 &nbsp;{{ item.emid }}&nbsp; 分钟</span
                >
                <span class="Gold-li2">
                  <i class="li2-con"></i>{{ item.num }} 金币</span
                >
              </div>
              <div class="Gold-ul2">每天一阅,来阅读吧</div>
            </div>
            <span
              class="Gold-span goids-span"
              v-if="!item.btn_flag"
              @click="btnFun(item.emid)"
              style="background-color: rgb(237 217 227)"
              >领取奖励</span
            >
            <span
              class="Gold-span goids-span"
              v-if="item.btn_flag"
              style="background-color: #8d9f8d; color: #fff"
              >已完成</span
            >
          </div>
        </main>
      </div>
      <!-- 图片区 -->
      <div class="img-items">
        <div class="img-item item1">
          <div class="item-text1">会员签到</div>
          <div class="item-text2">每天额外送礼劵</div>
        </div>
        <div class="img-item item2">
          <div class="item-text1">免费专区</div>
          <div class="item-text2">大量免费书籍</div>
        </div>
        <div class="img-item item3">
          <div class="item-text1">58到家</div>
          <div class="item-text2">服务随叫随到</div>
        </div>
      </div>
    </div>
  </div>
  <navfooterView></navfooterView>
</template>



<style lang="scss" scoped>
.app-make {
  background-color: rgb(244, 236, 243);
  .head-Mask {
    position: fixed;
    min-width: 375px;
    max-width: 750px;
    width: 100%;
    height: 160px;
    background-image: linear-gradient(
      90deg,
      rgb(185, 96, 218),
      rgb(243, 127, 128)
    );
    border-bottom-left-radius: 50% 20px;
    border-bottom-right-radius: 50% 20px;
  }
  .head {
    position: fixed;
    min-width: 375px;
    max-width: 750px;
    width: 100%;
    height: 43px;
    top: 0;
    // left: 0;
    z-index: 13;
    background-image: linear-gradient(
      90deg,
      rgb(185, 96, 218),
      rgb(243, 127, 128)
    );
    span {
      line-height: 43px;
    }
    .head-text {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      color: #fff;
      font-size: 18px;
    }
    .con-bz {
      position: absolute;
      top: 5px;
      right: 21px;
      // width: 25px;
      height: 30px;
      img {
        // width: 100%;
        height: 100%;
      }
    }
  }
  .content {
    position: relative;
    z-index: 8;
    box-sizing: border-box;
    padding: 0 15px;
    margin: 43px 0;
    //内容头部
    .content-head {
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      padding: 0 15px;
      font-size: 12px;
      margin-bottom: 16px;
      padding-top: 16px;
      .con-text {
        color: #fff;
        text-align: center;
        i {
          font-size: 16px;
        }
      }
      .content-con {
        width: 65px;
        height: 22px;
        color: rgb(244, 236, 243);
        line-height: 22px;
        text-align: center;
        border: 1px solid rgb(244, 236, 243);
        border-radius: 16px;
        margin-top: 3px;
      }
    }
    //签到区
    .content-Sign {
      position: relative;
      z-index: 11;
      width: 100%;
      background: #fff;
      border-radius: 12px;
      box-sizing: border-box;
      padding: 15px;
      .Sign-ul {
        position: relative;
        margin-bottom: 16px;
        .sign-span1 {
          font-size: 16px;
          font-weight: 600;
          margin-bottom: 5px;
        }
        .sign-span2 {
          font-size: 12px;
          color: rgb(185, 185, 193);
        }
      }
      .sign-con {
        position: absolute;
        top: 0px;
        right: 0px;
        font-size: 13px;
        width: 66px;
        height: 28px;
        line-height: 28px;
        color: rgb(231, 132, 80);
        border: 1px solid rgb(231, 132, 80);
        text-align: center;
        border-radius: 26px;
      }
      .Countersign-ul {
        display: flex;
        justify-content: space-between;

        .Countersign-li1 {
          position: relative;
          border-radius: 6px;
          width: 36px;
          height: 65px;
          background-color: rgb(255, 241, 232);
          .li1-con {
            position: absolute;
            top: 11px;
            left: 5px;
            width: 27px;
            height: 27px;
            background-image: url("../assets/img/amw.png");
            background-size: 100% 100%;
          }
          .li1-text {
            position: absolute;
            // width: 100%;
            line-height: 18px;
            height: 18px;
            font-size: 13px;
            bottom: 5px;
            left: 8px;
            color: rgb(231, 102, 38);
          }
        }
        .Countersign-li2 {
          position: relative;
          width: 36px;
          height: 65px;
          border-radius: 6px;
          background-color: rgb(246, 247, 249);
          .li2-con {
            position: absolute;
            top: 11px;
            left: 6px;
            width: 27px;
            height: 27px;
            background-image: url("../assets/img/amz.png");
            background-size: 100% 100%;
          }
          .li2-text {
            position: absolute;
            width: 100%;
            line-height: 18px;
            height: 18px;
            font-size: 13px;
            bottom: 5px;
            left: 6px;
            color: rgb(220, 220, 220);
          }
        }
      }
    }
    .Sign-Button {
      width: 100%;
      margin: 16px 0;
      padding: 0 41px;
      box-sizing: border-box;
      .button-submit {
        height: 42px;
        display: flex;
        background-image: linear-gradient(90deg, #fcc47c, #fe5955);
        border-radius: 32px;
        line-height: 42px;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 15px;
        i {
          display: inline-block;
          width: 23px;
          height: 24px;
          margin-right: 10px;
          background: url("../assets/img/al2.png");
          background-size: 100% 100%;
        }
      }
      .button-submit1 {
        background-image: linear-gradient(90deg, #e4d6c5, #d4bebe);
        color: #fff;
      }
    }
    .Sign-member {
      position: relative;
      display: flex;
      width: 100%;

      .i1 {
        width: 16px;
        height: 16px;
        display: block;
        position: absolute;
        top: -1px;
        left: 17px;
        background-image: url("../assets/img/aly.png");
        background-size: 100% 100%;
      }
      .member-text1 {
        font-size: 13px;
        color: rgb(170, 142, 108);
        margin-right: 45px;
        margin-left: 38px;
      }
      .member-text2 {
        position: relative;
        font-size: 12px;
        color: #a5a5ae;
        .icon {
          position: absolute;
          top: 2px;
          right: -15px;
          font-size: 12px;
        }
      }
    }

    // 视频阅读区
    .content-video {
      width: 100%;
      //    min-height: 600px;
      background-color: #fff;
      margin-top: 10px;
      border-radius: 6px;
      padding: 15px;
      box-sizing: border-box;
      .video-Gold {
        position: relative;
        margin-bottom: 10px;
        .Gold-li1 {
          font-size: 14px;

          .li1-con {
            color: #f3996b;
          }
        }
        .Gold-li2 {
          position: relative;
          font-size: 14px;
          color: #f3996b;
          margin-left: 28px;
          .li2-con {
            position: absolute;
            top: -1px;
            left: -18px;
            width: 14px;
            height: 14px;
            display: block;
            background-image: url("../assets/img/am4.png");
            background-size: 100% 100%;
          }
        }
        .Gold-ul2 {
          font-size: 13px;
          color: #82818f;
          margin: 5px 0;
        }
        .Gold-span {
          position: absolute;
          top: 10px;
          right: 0px;
          font-size: 13px;
          color: #aa62d8;
          width: 66px;
          height: 27px;
          background-color: #f5dafb;
          display: block;
          line-height: 27px;
          text-align: center;
          border-radius: 16px;
        }
      }
      .br {
        width: 100%;
        height: 1px;
        background-color: #f6f6f6;
      }
      .Daily {
        width: 100%;
        position: relative;
        margin: 10px 0;

        .Daily-li1 {
          font-size: 14px;
          margin-bottom: 5px;
        }
        .Daily-li2 {
          font-size: 13px;
          color: rgb(143, 143, 156);
        }
        .Daily-span {
          position: absolute;
          top: 0px;
          right: 0px;
          .span-text,
          .icon1 {
            font-size: 13px;
            color: rgb(143, 143, 156);
          }
          .span-text {
            i {
              color: #000;
            }
          }
        }
      }
      .Daily-items {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;
        .Daily-item {
          position: relative;
          width: 53px;
          height: 63.5px;
          background-color: rgb(255, 248, 242);
          border: 2px solid rgb(246, 126, 76);
          border-radius: 6px;
          .span1 {
            position: absolute;
            width: 46.5px;
            height: 15.5px;
            background-color: rgb(250, 140, 77);
            top: -9px;
            left: 8%;
            line-height: 15.5px;
            color: #fff;
            font-size: 10px;
            transform: scale(0.9);
            border-radius: 3px;
            text-align: center;
          }
          .span2 {
            position: relative;
            margin-top: 10px;
            color: rgb(234, 112, 52);
            text-align: center;
            padding-top: 4px;
            display: flex;
            font-size: 14px;
            .span2-con {
              top: 4px;
              left: 7px;
              width: 18px;
              height: 15.5px;
              display: inline-block;
              background-image: url("../assets/img/r4.png");
              background-size: 100% 100%;
            }
          }
          .span3 {
            position: absolute;
            width: 54px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            font-size: 10px;
            bottom: -2px;
            left: 0px;
            color: #fff;
            border-radius: 3px;
            background-image: linear-gradient(90deg, #fcc47c, #fe5955);
          }
        }
        .Daily_flag {
          .span3 {
            background-image: linear-gradient(90deg, #6a6967, #847f7f);
          }
        }
      }
      .goids {
        margin: 15px 0;
        .goids-li2 {
          margin-left: 27px;
          .lis-con {
            width: 16px;
            height: 13px;
            top: 1px;
            background-image: url("../assets/img/alw.png");
            background-size: 100% 100%;
          }
        }
        .goids-span {
          background-color: rgb(252, 231, 217);
          color: rgb(238, 96, 29);
        }
      }
    }
    //图片区
    .img-items {
      width: 100%;
      min-height: 143px;
      margin-top: 15px;
      display: flex;
      justify-content: space-between;
      .img-item {
        width: 110px;
        height: 78px;
        background: #f5dafb;
        border-radius: 6px;
        box-sizing: border-box;
        padding-top: 10px;
        padding-left: 10px;
        .item-text1 {
          font-size: 14px;
          margin-bottom: 5px;
        }
        .item-text2 {
          font-size: 12px;
        }
      }
      .item1 {
        background-image: linear-gradient(
          90deg,
          rgb(84, 84, 80),
          rgb(40, 39, 37)
        );
        color: rgb(220, 206, 182);
      }
      .item2 {
        background-image: linear-gradient(
          90deg,
          rgb(255, 207, 148),
          rgb(255, 163, 19)
        );
        color: #fff;
      }
      .item3 {
        background-image: linear-gradient(
          90deg,
          rgb(76, 224, 188),
          rgb(21, 172, 133)
        );
        color: #fff;
      }
    }
  }
}
</style>